package exam.bak.netease;

import javafx.util.Pair;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class P4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //1. 录入数据
        int[] params = Arrays.stream(scanner.nextLine().trim().split("\\s+")).mapToInt(Integer::parseInt).toArray();
        int n = params[0];
        int a = params[1];
        int b = params[2];
        char[][] board = new char[n][n];
        for (int i = 0; i < n; i++) {
            board[i] = scanner.nextLine().trim().toCharArray();
        }
        // 2. 执行计算
        int[][] dp = new int[n][n];
        dp[0][0] = 0;
        int minStartCost = board[0][0] == '*' ? 0 : Integer.MAX_VALUE;
        // 2.1 赋值第一行
        for (int i = 1; i < n; i++) {
            char c = board[0][i];
            int cost = 0;
            if (c == '.') {
                cost = dp[0][i - 1];
            } else if (c == '*') {
                cost = dp[0][i - 1];
                minStartCost = Math.min(minStartCost, cost);
            } else if (c == '#') {
                cost = dp[0][i - 1] + a;
            }
            dp[0][i] = cost;
        }
        //2.2 赋值其他
        for (int row = 1; row < n; row++) {
            for (int col = 0; col < n; col++) {
                char c = board[row][col];
                int cost = 0;
                if (c == '.') {
                    cost = col - 1 >= 0 ? Math.min(dp[row - 1][col], dp[row][col - 1]) : dp[row - 1][col];
                } else if (c == '*') {
                    cost = col - 1 >= 0 ? Math.min(dp[row - 1][col], dp[row][col - 1]) : dp[row - 1][col];
                    cost = Math.min(cost, minStartCost + b);
                    minStartCost = Math.min(minStartCost, cost);
                } else if (c == '#') {
                    cost = col - 1 >= 0 ? Math.min(dp[row - 1][col], dp[row][col - 1]) : dp[row - 1][col];
                    cost += a;
                }
                dp[row][col] = cost;
            }
            //重置本行的#
            for (int col = n - 1; col >= 0; col--) {
                if (board[row][col] == '#') {
                    dp[row][col] = col + 1 < n ? Math.min(dp[row][col], dp[row][col + 1]) : dp[row][col];
                }
            }
        }

        System.out.println(dp[n - 1][n - 1]);
    }


    public void dp(char[][] board, int n, int x, int y, int cost, List<Pair<Integer, Integer>> savedList, int[] minCost) {
        if (x == n - 1 && y == n - 1) {
            minCost[0] = Math.min(minCost[0], cost);
        } else {
            int[][] directions = {
                    {0, 1},
                    {0, -1},
                    {1, 0},
                    {-1, 0}
            };
            for (int[] direct : directions) {
                int nx = x + direct[0];
                int ny = y + direct[1];
                Pair<Integer, Integer> pair = new Pair<>(nx, ny);
                if (!savedList.contains(pair)) {
                    if (board[nx][ny] == '.') {
                        savedList.add(pair);
                        dp(board, n, nx, ny, cost, savedList, minCost);
                        savedList.remove(savedList.size() - 1);
                    } else if (board[nx][ny] == '#') {

                    }
                }
            }
        }
    }
}
